package com.example.frn.config;

import com.example.frn.interceptor.AuthInterceptor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.LinkedList;
import java.util.List;

@Configuration
@ConfigurationProperties(prefix = "auth.include")
@Data
public class WebConfig implements WebMvcConfigurer {
//    @Value("${paths}")
    List<String> paths = new LinkedList<>();
    @Autowired
    AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println(paths);
        // 重写这个方法，将自定义的拦截器完成注册
        registry.addInterceptor(authInterceptor)
                // 拦截所有请求
                .addPathPatterns(paths)
                // 放行登录和注册请求及其他需要放行的请求
                .excludePathPatterns("/api/v1/user/login", "/api/v1/user/register");
    }
}
